package org.gensokyo.shanbay

import java.sql.Timestamp
import java.time.ZoneOffset

import slick.driver.MySQLDriver.api._
/**
 * Created by liusen on 15-12-8.
 */
package object dao {
  /**
   * map between java.time.LocalDateTime and sql.Timestamp
   */
  implicit val JavaLocalDateTimeMapper = MappedColumnType.base[java.time.LocalDateTime,java.sql.Timestamp](
    d => Timestamp.from(d.toInstant(ZoneOffset.ofHours(0))),
    d => d.toLocalDateTime
  )

  /**
   * map between java.time.LocalDate and sql.Date
   */
  implicit val JavaLocalDateMapper = MappedColumnType.base[java.time.LocalDate,java.sql.Date](
    d =>  java.sql.Date.valueOf(d),
    d =>  d.toLocalDate
  )
}
